package com.neusoft.bizcore.activiti.repository.impl;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.neusoft.bizcore.activiti.model.LockData;
import com.neusoft.bizcore.activiti.model.QLockData;
import com.neusoft.bizcore.activiti.repository.CustomizedLockDataRepository;
import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.bizcore.web.support.Searchable;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedLockDataRepositoryImpl extends AbstractRepository
        implements CustomizedLockDataRepository {

	@Override
    public List<LockData> index(final Searchable searchable) {
        final QLockData qLockData = QLockData.lockData;
        final BooleanBuilder where = this.buildWhere(searchable);
        final JPAQuery<LockData> query =
                this.query().selectFrom(qLockData);
        query.where(where);
        return query.fetch();
    }

    @Override
    protected Class<?> getModelClass() {
        return LockData.class;
    }

    @Override
    public Page<LockData> search(final Pageable pageable, final Searchable searchable) {
        final QLockData qLockData = QLockData.lockData;
        final BooleanBuilder where = this.buildWhere(searchable);
        final JPAQuery<LockData> query = this.query().selectFrom(qLockData);
        query.where(where);
        return super.search(query, pageable);
    }

    private BooleanBuilder buildWhere(final Searchable searchable) {
        final BooleanBuilder where = new BooleanBuilder();
        return where;
    }
}
